package com.pureut.production.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.production.domain.LineStock;
import com.pureut.production.domain.dto.LineStockDto;
import com.pureut.production.domain.dto.LineStockSummaryDto;
import com.pureut.production.domain.vo.LineStockVo;
import com.pureut.production.domain.vo.UpdateLineStockStatusVo;
import com.pureut.production.service.ILineStockService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description 线边库存
 * @Date 23-02-21
 * @Author hl
 **/
@RestController
@RequestMapping("/lineStock")
public class LineStockController extends BaseController {

    @Resource
    private ILineStockService lineStockService;

    /**
     * 查询线边库存
     */
    @RequiresPermissions("productionTube:prostatistics:lineedge:list")
    @GetMapping("/list")
    public TableDataInfo list(LineStockVo lineStockVo) {
        startPage();
        List<LineStockDto> list = lineStockService.selectLineStockList(lineStockVo);
        return getDataTable(list);
    }

    /**
     * 查询线边库存汇总
     */
    @GetMapping("/listSummary")
    public TableDataInfo listSummary(LineStockVo lineStockVo) {
        startPage();
        List<LineStockSummaryDto> list = lineStockService.selectLineStockSummaryList(lineStockVo);
        return getDataTable(list);
    }

    /**
     * 根据物料号码获取线边库存数据（fegin调用）
     */
    @GetMapping("/getLineStockData")
    public AjaxResult getLineStockData(String materialNumber) {
        return AjaxResult.success(lineStockService.getLineStockData(materialNumber));
    }


    /**
     * 查询线边仓数据（冻结列表查询 feign调用）
     */
    @PostMapping("/getLineStockList")
    public AjaxResult getLineStockList(@RequestBody LineStockVo lineStockVo) {
        return AjaxResult.success(lineStockService.getLineStockList(lineStockVo));
    }

    /**
     * 批量修改线边仓数据状态 feign调用
     */
    @PostMapping("/updateLineStockStatus")
    public AjaxResult updateLineStockStatus(@RequestBody UpdateLineStockStatusVo updateLineStockStatusVo) {
        return AjaxResult.success(lineStockService.updateLineStockStatus(updateLineStockStatusVo));
    }

    /**
     * 通过物料号码修改线边仓物料冻结状态
     */
    @GetMapping("/updateStatusThaw")
    public void updateStatusThaw(String materialNumber) {
        lineStockService.updateStatusThaw(materialNumber);
    }

    /**
     * 新增线边仓数据
     */
    @PostMapping("/addLineStock")
    public AjaxResult addLineStock(@RequestBody LineStock lineStock) {
        return AjaxResult.success(lineStockService.addLineStock(lineStock));
    }

    /**
     * 批量新增线边仓数据
     */
    @PostMapping("/addBatchLineStock")
    public AjaxResult addBatchLineStock(@RequestBody List<LineStock> list) {
        return AjaxResult.success(lineStockService.addBatchLineStock(list));
    }

    /**
     * 批量删除线边仓数据(通过领料单号)
     */
    @PostMapping("/deleteBatchLineStock")
    public AjaxResult deleteBatchLineStock(@RequestBody String wareAlCode) {
        return AjaxResult.success(lineStockService.deleteBatchLineStock(wareAlCode));
    }


    /**
     * 删除线边仓数据
     */
    @GetMapping("/deleteLineStock")
    public AjaxResult deleteLineStock(String materialNumber) {
        return AjaxResult.success(lineStockService.deleteLineStock(materialNumber));
    }

}
